﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        int WordNum = 0;
        int num = 0;
        public Form1()
        {
            InitializeComponent();
            using (var db = new Model1())
            {
                label4.Text = "单词库共有"+db.worddata.Count().ToString()+"个单词";
                WordNum = db.worddata.Count();
                var word = db.worddata.SingleOrDefault(b => b.Id == 0);
                if (word != null) label1.Text = word.Explain.ToString();
            }
        }
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != '\r')
                return;
            using (var db = new Model1())
            {
                var word = db.worddata.SingleOrDefault(b => b.Id == num);
                if (word != null && word.Name == textBox1.Text)
                    label3.Text = "正确";
                else
                { 
                    label3.Text = "错误";
                    label2.Text = "正确答案：" + word.Name;
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            num++;
            if (num == WordNum) num = 0;
            using (var db = new Model1())
            {
                var word = db.worddata.SingleOrDefault(b => b.Id == num);
                if (word != null) label1.Text = word.Explain.ToString();
            }
            label3.Text = "";
            label2.Text = "";
        }
    }
}
